<?php
# Application
define('APP', dirname(__file__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR);

# Framework
require APP.'fw'.DIRECTORY_SEPARATOR.'init.php';

# Connection
fw::connect();

$id = db::escape($_GET['id']);

if(strlen($id) != 13) exit();

db::query('DELETE FROM `'.DB_PREFIX.'upload` WHERE `id`="'.$id.'"');

$result = db::query('SELECT `id`, `extension` FROM `'.DB_PREFIX.'Image` WHERE `upload_id`="'.$id.'"');
while($row = db::fetch($result, 'row'))
{
	db::query('DELETE FROM `'.DB_PREFIX.'Image` WHERE `id`='.$row[0]);
	
	unlink(APP.'upload'.DIRECTORY_SEPARATOR.'original'.DIRECTORY_SEPARATOR.$row[0].'.'.$row[1]);
}